package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {

	public List<Customer> findByFixedAreaIdIsNull();

	public List<Customer> findByFixedAreaId(String fixedAreaId);

	@Query("update Customer set fixedAreaId= ? where id=?")
	@Modifying
	public void updatefixedtest(String fixedAreaId, Integer id);

	// 为以关联定区客户进行提交
	@Query("update Customer set fixedAreaId= ? where id=?")
	@Modifying
	public void updateassigncustomer(String fixedAreaId, Integer id);

	// 取消客户和定区的关联
	@Query("update Customer set fixedAreaId= null where fixedAreaId=?")
	@Modifying
	public void updateNoassigncustomer(String fixedAreaId);

	// 邮箱激活
	public Customer findByTelephone(String telephone);

	@Query("update Customer set type=1 where telephone=?")
	@Modifying
	public void updateType(String telephone);

	//客户登录校验
	public Customer findByTelephoneAndPassword(String telephone, String password);

	//添加根据地址  获取定区编码  下一步是 修改 bos_management 的OrderService
	@Query("select fixedAreaId from Customer where address=?")
	public String findFixedAreaIdByAddress(String address);

}
